var commonInfoXMLPath = "interfaceXML/commonInfo.xml";


/***********************************
 * 基础函数
 ************************************/
var Timer = {
	_data: {},
	start: function(key) {
		Timer._data[key] = new Object();
		Timer._data[key].startTime = new Date();
		Timer._data[key].endTime = null;
		Timer._data[key].elapsedTime = null;
	},
	stop: function(key) {
		var time = Timer._data[key].startTime;
		if (time) {
			Timer._data[key].endTime = new Date();
			Timer._data[key].elapsedTime = Timer._data[key].endTime - time;
		}
	},
	getStartTime: function(key) {
		return Timer._data[key].startTime;
	},
	getEndTime: function(key) {
		return Timer._data[key].endTime;
	},
	getElapsedTime: function(key) {
		return Timer._data[key].elapsedTime;
	}
};

/**
 * <param name="x">待显示的日期时间，例如new Date()</param>
 * <param name="y">需要显示的格式，例如yyyy-MM-dd hh:mm:ss:SSSS</param>
 */
function date2str(x,y) {
	var z = {M:x.getMonth()+1,d:x.getDate(),H:x.getHours(),m:x.getMinutes(),s:x.getSeconds()};
	y = y.replace(/(M+|d+|H+|m+|s+)/g,function(v) {return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-2)});
	y = y.replace(/(S+)/g,function(v) {return x.getMilliseconds().toString().slice(-v.length)});
	return y.replace(/(y+)/g,function(v) {return x.getFullYear().toString().slice(-v.length)});
}

/**
 * 时间处理
 * 以yyyyMMdd的格式返回当前时间
 */
Date.prototype.yyyyMMdd = function() {
   var yyyy = this.getFullYear().toString();
   var MM = (this.getMonth()+1).toString(); // getMonth() is zero-based
   var dd  = this.getDate().toString();
   return yyyy + (MM[1]?MM:"0"+MM[0]) + (dd[1]?dd:"0"+dd[0]); // padding
};

/**
 * 时间处理
 * 以HHmm的格式返回当前时间
 */
Date.prototype.HHmm = function() {
   var HH = this.getHours().toString();
   var mm = (this.getMinutes()).toString();
   return (HH[1]?HH:"0"+HH[0]) + (mm[1]?mm:"0"+mm[0]);  // padding
};

/**
 * 如果小于10，前面补充0
 */
function checkTime(i){
	var str = i.toString();
	return str[1]?str:"0"+str[0];
}

/**
 * Copy some content to clipboard
 */
function copyToClipboard(content) {
	if (window.clipboardData && clipboardData.setData) {
		clipboardData.setData('text', content);
	}
}


/**
 * Load XML document
 */
function loadXMLDoc(dname) {
	try {
		//Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	catch(e) {
		try {
			//Firefox, Mozilla, Opera, etc.
			xmlDoc=document.implementation.createDocument("","",null);
		}
		catch(e) {
			alert(e.message);
		}
	}

	try	{
		xmlDoc.async=false;
		xmlDoc.load(dname);
		return(xmlDoc);
	}
	catch(e) {
		alert(e.message);
	}
	return(null);
}

var Parameter = {
	createNew: function(url,type,operation,fatherMobile1,fatherMobile2,childMobile1,childMobile2,precision) {
		var parameter = {};
		parameter.url = url;
		parameter.type = type;
		parameter.operation = operation;
		parameter.fatherMobile1 = fatherMobile1;
		parameter.fatherMobile2 = fatherMobile2;
		parameter.childMobile1 = childMobile1;
		parameter.childMobile2 = childMobile2;
		parameter.precision = precision;

		return parameter;
	}
}


/**
 * 延迟加载方法
 * 实现不用每次调用createXMLHttpRequest函数的时候都判断一下浏览器是IE7+还是IE6
 */
function createXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		createXMLHttpRequest = function() {
			// code for IE7+, Firefox, Chrome, Opera, Safar
			return new XMLHttpRequest();
		};
	} else {
		createXMLHttpRequest = function() {
			// code for IE6, IE5
			return new ActiveXObject("Microsoft.XMLHTTP");
		};
	}
	return createXMLHttpRequest();
}


/**
 * 从XML文档读取日志
 */
function readLog() {
	// Log file name
	var logFileName = "log/" + document.getElementById("logFileName").value;
	var xmlDoc = loadXMLDoc(logFileName);

	var logsDoc = xmlDoc.getElementsByTagName("log");
	var log = new Object();
	log.request = "";
	log.response = "";
	log.url = "";
	log.type = "";
	log.operation = "";
	log.precision = "";
	log.fatherMobile1 = "";
	log.fatherMobile2 = "";
	log.childMobile1 = "";
	log.childMobile2 = "";
	log.requestTime = "";
	log.elapsedTime = "";

	for (var i = logsDoc.length; i--; ) {
		var logDoc = logsDoc[i];
		log.request =  logDoc.childNodes[0].firstChild.xml;
		log.response =  logDoc.childNodes[1].childNodes[0].xml + "\r\n" + logDoc.childNodes[1].childNodes[1].xml;
		log.url = logDoc.childNodes[2].firstChild.nodeValue;
		log.type = logDoc.childNodes[3].firstChild.nodeValue;

		if (null != logDoc.childNodes[4].firstChild)
		{
			log.operation = logDoc.childNodes[4].firstChild.nodeValue;
		}

		if (null != logDoc.childNodes[5].firstChild)
		{
			log.precision = logDoc.childNodes[5].firstChild.nodeValue;
		}		
		
		if (null != logDoc.childNodes[6].firstChild)
		{
			log.fatherMobile1 = logDoc.childNodes[6].firstChild.nodeValue;
		}

		if (null != logDoc.childNodes[7].firstChild)
		{
			log.fatherMobile2 = logDoc.childNodes[7].firstChild.nodeValue;
		}

		if (null != logDoc.childNodes[8].firstChild)
		{
			log.childMobile1 = logDoc.childNodes[8].firstChild.nodeValue;
		}

		if (null != logDoc.childNodes[9].firstChild)
		{
			log.childMobile2 = logDoc.childNodes[9].firstChild.nodeValue;
		}

		if (null != logDoc.childNodes[10].firstChild)
		{
			log.requestTime = logDoc.childNodes[10].firstChild.nodeValue;
		}

		if (null != logDoc.childNodes[11].firstChildnodeValue)
		{
			log.elapsedTime = logDoc.childNodes[11].firstChildnodeValue;
		}		

		var parameter = Parameter.createNew(log.url,log.type,log.operation,log.fatherMobile1,log.fatherMobile2,log.childMobile1,log.childMobile2,log.precision);

		autoCreateHistory(log.request,log.response, parameter,log.requestTime, log.elapsedTime);
	}
}

function initLogFileName() {
	// Log file name
	logFileNameHTML = document.getElementById("logFileName");
	logFileNameHTML.value = "log-"+date2str(new Date(),"yyyy-MM-dd")+".xml";
}

function autoCreateHistory(requestText,responseText,parameter,requestTime,elapsedTime) {
	// Create request and response history
	var historyHTML = document.getElementById("history");
		
	var tbody = historyHTML.tBodies[0];

	var row = tbody.insertRow(0);

	row.insertCell(0);
	row.cells[0].innerText = requestText; 		

	row.insertCell(1);
	row.cells[1].innerText = responseText; 
	
	row.insertCell(2);
	row.cells[2].innerText = parameter.url; 
	row.cells[2].style.display = "none";
	
	row.insertCell(3);
	row.cells[3].innerText = parameter.type;
	row.cells[3].style.display = "none";

	row.insertCell(4);
	row.cells[4].innerText = parameter.operation;
	row.cells[4].style.display = "none";

	row.insertCell(5);
	row.cells[5].innerText = parameter.precision;
	row.cells[5].style.display = "none";

	row.insertCell(6);
	row.cells[6].innerText = parameter.fatherMobile1;

	row.insertCell(7);
	row.cells[7].innerText = parameter.fatherMobile2;

	row.insertCell(8);
	row.cells[8].innerText = parameter.childMobile1;

	row.insertCell(9);
	row.cells[9].innerText = parameter.childMobile2;

	row.insertCell(10);
	row.cells[10].innerText = requestTime;

	row.insertCell(11);
	row.cells[11].innerText = elapsedTime;

	
	var rowBackgroundColor = row.style.backgroundColor;

	// 设置相邻行颜色不一样
	if( tbody.rows.length & 1 ) {
		rowBackgroundColor = "#FFFFFF";
	}

	var transPatt = new RegExp('error');
	// 如果返回的结果包含error字符串，则将该行设置成黄色
	if (transPatt.test(responseText)) {
		rowBackgroundColor = "#FFFF00";
	}
	row.style.backgroundColor = rowBackgroundColor;


	// 设置鼠标入和画出后的背景颜色
	//var rowBackgroundColor = row.style.backgroundColor;

	row.onclick = function() {
		showSelectedLog(this);
	}
	
	row.onmouseover = function() {
		row.style.backgroundColor = "#f895c2";
	}
	
	row.onmouseout = function() {
		row.style.backgroundColor = rowBackgroundColor;
	}
} 


function saveHistory() {
	var doc = document;
	var fso = new ActiveXObject("Scripting.FileSystemObject");
	var logFileName = doc.getElementById("logFileName").value;
	logFileName = location.pathname.substring(1,location.pathname.lastIndexOf('/')+1) + "Log/" + logFileName;
	var file = fso.CreateTextFile(logFileName, true, true);
	var strLog = ['<?xml version="1.0" encoding="utf-16"?>\r\n<Logs>\r\n'];

	// Create request and response history
	var historyHTML = doc.getElementById("history");

	var tbody = historyHTML.tBodies[0];
	var rows = tbody.rows;
	strLogLength = strLog.length;
	for (var i = 0,length = rows.length; i < length; i++) {
		var row = rows[i];
		strLog[strLogLength++] = '    <log>\r\n';
		strLog[strLogLength++] = '        <request>\r\n';
		strLog[strLogLength++] = row.cells[0].innerText;
		strLog[strLogLength++] = '</request>\r\n';
		strLog[strLogLength++] = '        <response>\r\n';
		strLog[strLogLength++] = row.cells[1].innerText.replace(/encoding="[\s\S]*"/,'encoding="utf-16"');
		strLog[strLogLength++] = '</response>\r\n';
		strLog[strLogLength++] = '        <url>';
		strLog[strLogLength++] = row.cells[2].innerText.replace(/&/g,'&amp;');
		strLog[strLogLength++] = '</url>\r\n';
		strLog[strLogLength++] = '        <type>';
		strLog[strLogLength++] = row.cells[3].innerText;
		strLog[strLogLength++] = '</type>\r\n';
		strLog[strLogLength++] = '        <operation>';
		strLog[strLogLength++] = row.cells[4].innerText;
		strLog[strLogLength++] = '</operation>\r\n';
		strLog[strLogLength++] = '        <precision>';
		strLog[strLogLength++] = row.cells[5].innerText;
		strLog[strLogLength++] = '</precision>\r\n';
		strLog[strLogLength++] = '        <fatherMobile1>';
		strLog[strLogLength++] = row.cells[6].innerText;
		strLog[strLogLength++] = '</fatherMobile1>\r\n';
		strLog[strLogLength++] = '        <fatherMobile2>';
		strLog[strLogLength++] = row.cells[7].innerText;
		strLog[strLogLength++] = '</fatherMobile2>\r\n';
		strLog[strLogLength++] = '        <childMobile1>';
		strLog[strLogLength++] = row.cells[8].innerText;
		strLog[strLogLength++] = '</childMobile1>\r\n';
		strLog[strLogLength++] = '        <childMobile2>';
		strLog[strLogLength++] = row.cells[9].innerText;
		strLog[strLogLength++] = '</childMobile2>\r\n';
		strLog[strLogLength++] = '        <requestTime>';
		strLog[strLogLength++] = row.cells[10].innerText;
		strLog[strLogLength++] = '</requestTime>\r\n';
		strLog[strLogLength++] = '        <elapsedTime>';
		strLog[strLogLength++] = row.cells[11].innerText;
		strLog[strLogLength++] = '</elapsedTime>\r\n';
		strLog[strLogLength++] = '    </log>\r\n';
	}
	strLog[strLogLength++] = '</Logs>';
	file.WriteLine(strLog.join(""));
	file.close();
	alert("日志文件保存成功！");
}


// 清除日志表内容
function clearLog() {
	var logTableHTML = document.getElementById("history");
	var old_tbody = logTableHTML.tBodies[0];
	var new_tbody = document.createElement('tbody');
	logTableHTML.replaceChild(new_tbody, old_tbody);
}



/**
 * Load common info for XML document.
 */
function loadCommonInfoXMLDoc(dname) {
	var xmlDoc = loadXMLDoc(dname);
	var doc = document;
	

	/**
	 * 解析接口文件名
	 */
	var interfaceXMLsDoc = xmlDoc.getElementsByTagName("interfaceXML");
	var typesHTML = doc.getElementById("types");

	// 清除原有数据
	typesHTML.innerHTML = "";

	var firstItem = "--Type--";
	typesHTML.add(new Option(firstItem,firstItem));	
	for(var i = interfaceXMLsDoc.length; i--; ) {
		var ch = interfaceXMLsDoc[i].firstChild;
		var name = ch.firstChild.nodeValue;
		var fileName = ch.nextSibling.firstChild.nodeValue;

		typesHTML.add(new Option(name,fileName));
	}


	/**
	 * 解析操作类型部分
	 */
	var operationsDoc = xmlDoc.getElementsByTagName("operation");
	var operationsHTML = doc.getElementById("operations");

	// 清除原有数据
	operationsHTML.innerHTML = "";

	var firstItem = "--Operations--";
	operationsHTML.add(new Option(firstItem,firstItem));	
	for(var i = operationsDoc.length; i--; ) {
		var ch = operationsDoc[i].firstChild;
		var name = ch.firstChild.nodeValue;
		var value = ch.nextSibling.firstChild.nodeValue;

		operationsHTML.add(new Option(name,value));
	}



	/**
	 * 解析电话号码部分
	 */
	var phonesDoc = xmlDoc.getElementsByTagName("phone");
	var fatherMobilesHTML1 = doc.getElementById("father_mobiles1");
	var fatherMobilesHTML2 = doc.getElementById("father_mobiles2");
	var childMobilesHTML1 = doc.getElementById("child_mobiles1");
	var childMobilesHTML2 = doc.getElementById("child_mobiles2");

	// 清除原有数据
	fatherMobilesHTML1.innerHTML = "";
	fatherMobilesHTML2.innerHTML = "";
	childMobilesHTML1.innerHTML = "";
	childMobilesHTML2.innerHTML = "";

	firstItem = "--Father Mobile--";
	fatherMobilesHTML1.add(new Option(firstItem,firstItem));
	fatherMobilesHTML2.add(new Option(firstItem,firstItem));
	firstItem = "--Child Mobile--";
	childMobilesHTML1.add(new Option(firstItem,firstItem));
	childMobilesHTML2.add(new Option(firstItem,firstItem));
	var phoneDoc = null;
	for(var i = phonesDoc.length; i--; ) {
		phoneDoc =  phonesDoc[i].firstChild.nodeValue;
		fatherMobilesHTML1.add( new Option(phoneDoc,phoneDoc));
		fatherMobilesHTML2.add( new Option(phoneDoc,phoneDoc));
		childMobilesHTML1.add(new Option(phoneDoc,phoneDoc));
		childMobilesHTML2.add(new Option(phoneDoc,phoneDoc));
	}

	/**
	 * 解析精度类型
	 */
	var precisionsDoc = xmlDoc.getElementsByTagName("precision");
	var precisionsHTML = doc.getElementById("precisions");

	// 清除原有数据
	precisionsHTML.innerHTML = "";

	var firstItem = "--Precisions--";
	precisionsHTML.add(new Option(firstItem,firstItem));	
	for(var i = precisionsDoc.length; i--; ) {
		var ch = precisionsDoc[i].firstChild;
		var name = ch.firstChild.nodeValue;
		var value = ch.nextSibling.firstChild.nodeValue;

		precisionsHTML.add(new Option(name,value));
	}


	/**
	 * 解析网址部分
	 */
	var websitesDoc = xmlDoc.getElementsByTagName("website");
	var website = new Object();
	var websitesHTML = doc.getElementById("websites");
	var testingURLsHTML = doc.getElementById("testingURLs");

	// 清除原有数据
	websitesHTML.innerHTML = "";
	testingURLsHTML.innerHTML = "";

	firstItem = "--URL--";
	testingURLsHTML.add(new Option(firstItem,firstItem));
	var websiteHTML = doc.createDocumentFragment();
	for(var i = websitesDoc.length; i--; ) {
		var ch = websitesDoc[i].firstChild;

		website.name = ch.firstChild.nodeValue;
		website.url = ch.nextSibling.firstChild.nodeValue;

		var lab = doc.createElement("label");
		lab.innerHTML = website.name+":";
		lab.className="label";

		var hyperLink = doc.createElement("a");
		hyperLink.href = website.url;
		hyperLink.innerHTML = website.url;

		websiteHTML.appendChild(lab);
		websiteHTML.appendChild(hyperLink);
		websiteHTML.appendChild(doc.createElement('br'));

		//添加测试URL
		testingURLsHTML.add(new Option(website.name,website.url));

	}
	websitesHTML.appendChild(websiteHTML);
}



var xmlDoc = null;
/**
 * 加载报文XML文件
 */
function loadReporter() {
	var xmlFileName = "interfaceXML/" + document.getElementById("type").value;
	xmlDoc = loadXMLDoc(xmlFileName);
	var doc = document;
	var requestHTML = doc.getElementById("request");

	requestHTML.value = xmlDoc.xml;
}

/**
 * 修改订购、重置或退订报文的参数
 **/
function changeParameter() {
	var doc = document;
	var url = doc.getElementById("testingURL").value;
	var type = doc.getElementById("type").value;
	var operation = doc.getElementById("operation").value;
	var fatherMobile1 = doc.getElementById("father_mobile1").value;
	var fatherMobile2 = doc.getElementById("father_mobile2").value;
	var childMobile1 = doc.getElementById("child_mobile1").value;
	var childMobile2 = doc.getElementById("child_mobile2").value;
	var precision = doc.getElementById("precision").value;

	if ("" == url)
	{
		alert("请选择URL！");
		return;
	}

	if ("" == type)
	{
		alert("请选择Type！");
		return;
	}

	if ("" == operation)
	{
		alert("请选择operation！");
		return;
	}
	if ("" == precision)
	{
		alert("请选择precision！");
		return;
	}

	loadReporter();
	var CDATA = xmlDoc.getElementsByTagName("SvcCont")[0].firstChild;
	var CDATADoc = new ActiveXObject("Microsoft.XMLDOM");
	CDATADoc.async = false;
	CDATADoc.loadXML(CDATA.nodeValue);


	var oprCodeDoc = CDATADoc.getElementsByTagName("OprCode");
	var IDValueDoc = CDATADoc.getElementsByTagName("IDValue");
	var ParentID1Doc = CDATADoc.getElementsByTagName("ParentID1");
	var ParentID2Doc = CDATADoc.getElementsByTagName("ParentID2");
	var BizCodeDoc = CDATADoc.getElementsByTagName("BizCode");
	var BizType = CDATADoc.getElementsByTagName("BizType")[0].firstChild.nodeValue;
	

	// 子卡订购
	if ("01" == precision || "02" == precision)
	{
		if ("" == childMobile1)
		{
			alert("请输入childMobile1！");
			return;
		}

		//辽宁亲情通
		if (BizType == "02")
		{
			if ("" == fatherMobile1)
			{
				alert("请输入fatherMobile1！");
				return;
			}
			
			oprCodeDoc[0].firstChild.nodeValue = operation;
			IDValueDoc[0].firstChild.nodeValue = childMobile1;
			ParentID1Doc[0].firstChild.nodeValue = fatherMobile1;
			ParentID2Doc[0].firstChild.nodeValue = fatherMobile2;
			BizCodeDoc[0].firstChild.nodeValue = precision;
		}
		//全网订购
		else if (BizType == "BJQQT")
		{
			oprCodeDoc[0].firstChild.nodeValue = operation;
			IDValueDoc[0].firstChild.nodeValue = childMobile1;
			BizCodeDoc[0].firstChild.nodeValue = precision;
		}
	}

	//父卡订购
	else if ("03" == precision || "04" == precision)
	{
		if ("" == fatherMobile1)
		{
			alert("请输入fatherMobile1！");
			return;
		}
		//辽宁亲情通
		if (BizType == "02")
		{
			if ("" == childMobile1)
			{
				alert("请输入childMobile1！");
				return;
			}
			
			oprCodeDoc[0].firstChild.nodeValue = operation;
			IDValueDoc[0].firstChild.nodeValue = fatherMobile1;
			ParentID1Doc[0].firstChild.nodeValue = childMobile1;
			ParentID2Doc[0].firstChild.nodeValue = childMobile2;
			BizCodeDoc[0].firstChild.nodeValue = precision;
		}
		//全网订购
		else if (BizType == "BJQQT")
		{
			 oprCodeDoc[0].firstChild.nodeValue = operation;
			 IDValueDoc[0].firstChild.nodeValue = fatherMobile1;
			 BizCodeDoc[0].firstChild.nodeValue = precision;
		}
	}

	CDATA.nodeValue = CDATADoc.xml;
	requestHTML.value = xmlDoc.xml;
}


/**
 * 修改授权报文的参数
 **/
function setParameter4Authorize() {
	var doc = document;
	var url = doc.getElementById("testingURL").value;
	var type = doc.getElementById("type").value;
	var fatherMobile1 = doc.getElementById("father_mobile1").value;
	var childMobile1 = doc.getElementById("child_mobile1").value;

	if ("" == url)
	{
		alert("请选择URL！");
		return;
	}

	if ("" == type)
	{
		alert("请选择Type！");
		return;
	}

	if ("" == childMobile1)
	{
		alert("请输入childMobile1！");
		return;
	}

	if ("" == fatherMobile1)
	{
		alert("请输入fatherMobile1！");
		return;
	}

	loadReporter();
	var sourceDoc = xmlDoc.getElementsByTagName("source");
	var destDoc = xmlDoc.getElementsByTagName("dest");

	sourceDoc[0].firstChild.nodeValue = fatherMobile1;
	destDoc[0].firstChild.nodeValue = childMobile1;
	
	requestHTML.value = xmlDoc.xml;
}


//设置request textarea
function setRequest(Action) {
	requestHTML.innerHTML = Action;
}

	//设置request textarea
function setResponse(responseText) {
	responseHTML.value = responseText;
}


function showSelectedLog(logRow) {
	var doc = document;
	var requestHTML = doc.getElementById("request");
	var responseHTML = doc.getElementById("response");
	var urlHTML = doc.getElementById("testingURL");
	var typeHTML = doc.getElementById("type");
	var operationHTML = doc.getElementById("operation");
	var fatherMobile1HTML = doc.getElementById("father_mobile1");
	var fatherMobile2HTML = doc.getElementById("father_mobile2");
	var childMobile1HTML = doc.getElementById("child_mobile1");
	var childMobile2HTML = doc.getElementById("child_mobile2");
	var precisionHTML = doc.getElementById("precision");
	
	requestHTML.value = logRow.cells[0].innerText;
	responseHTML.value = logRow.cells[1].innerText;
	urlHTML.value = logRow.cells[2].innerText;
	typeHTML.value = logRow.cells[3].innerText;
	operationHTML.value = logRow.cells[4].innerText;
	precisionHTML.value = logRow.cells[5].innerText;
	fatherMobile1HTML.value = logRow.cells[6].innerText;
	fatherMobile2HTML.value = logRow.cells[7].innerText;
	childMobile1HTML.value = logRow.cells[8].innerText;
	childMobile2HTML.value = logRow.cells[9].innerText;	
}

// Show websites div
function showWebsites() {
	var websites = document.getElementById("websites");
	websites.style.display = websites.style.display=="none"?"":"none";
}

//发起请求的textarea
var requestHTML = null;
//相应的textarea
var responseHTML = null;

var xmlhttp = null;

function init() {
	initLogFileName();

	var doc = document;

	// Request textarea
	requestHTML = doc.getElementById("request");
	
	// Response textarea
	responseHTML = doc.getElementById("response");
	
	// POST button
	var post = doc.getElementById("post");
	
	// Copy request button
	var copyRequest = doc.getElementById("copyRequest");
	
	// testing URL
	var testingURLHTML = doc.getElementById("testingURL");

	xmlhttp = createXMLHttpRequest();
	loadCommonInfoXMLDoc(commonInfoXMLPath);

	copyRequest.onclick = function() {
		copyToClipboard(requestHTML.value);
	};
	
	post.onclick = function() {
		var url = doc.getElementById("testingURL").value;
		var type = doc.getElementById("type").value;
		var operation = doc.getElementById("operation").value;
		var fatherMobile1 = doc.getElementById("father_mobile1").value;
		var fatherMobile2 = doc.getElementById("father_mobile2").value;
		var childMobile1 = doc.getElementById("child_mobile1").value;
		var childMobile2 = doc.getElementById("child_mobile2").value;
		var precision = doc.getElementById("precision").value;
		
		var parameter = Parameter.createNew(url,type,operation,fatherMobile1,fatherMobile2,childMobile1,childMobile2,precision);
		postReport(parameter,requestHTML.value);
		
	};
}

function postReport(parameter,content) {
	Timer.start('manualTesting');
	xmlhttp.open("POST",parameter.url,true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send(content);

	xmlhttp.onreadystatechange=function() {
		//Clear the content which came back at last time;
		responseHTML.value = "";
		
		var loadingDiv = document.getElementById("loadingDiv");
		// 插入loading图
		loadingDiv.innerHTML = "<img src='image/loading.gif' />";
		// 显示loading层
		loadingDiv.style.display = "";
		
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {				
			Timer.stop('manualTesting');
			// 数据处理完毕之后，将loading层再隐藏掉
			loadingDiv.style.display = "none";
			
			setResponse(xmlhttp.responseText);
			
			autoCreateHistory(content,xmlhttp.responseText, parameter,date2str(Timer.getStartTime('manualTesting'),"HH:mm:ss:SSSS yyyy-MM-dd"), Timer.getElapsedTime('manualTesting')+" ms");
		}
	}
}

init();